function [ vsegment tree ] = Findcurseg( axisx_L,axisy_L,axisz_L,tree )
%FINDCURSEG Summary of this function goes here
%   Detailed explanation goes here
label=1;
vsegment=[];
if label==1
    for i=1:tree.element1.segments_num
        if tree.element1.segments(i).subseg~=2
            row_num=size(tree.element1.segments(i).end,1);
            if all(tree.element1.segments(i).end(row_num,:)<axisx_L) && all(tree.element1.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element1.segments(i).rad;
                vsegment.level=tree.element1.segments(i).level;
                vsegment.istrunk=tree.element1.segments(i).istrunk;
                vsegment.start=tree.element1.segments(i).start;
                vsegment.end=tree.element1.segments(i).end;
                tree.element1.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element1.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element2.segments_num
        if tree.element2.segments(i).subseg~=2
            row_num=size(tree.element2.segments(i).end,1);
            if all(tree.element2.segments(i).end(row_num,:)<axisx_L) && all(tree.element2.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element2.segments(i).rad;
                vsegment.level=tree.element2.segments(i).level;
                vsegment.istrunk=tree.element2.segments(i).istrunk;
                vsegment.start=tree.element2.segments(i).start;
                vsegment.end=tree.element2.segments(i).end;
                tree.element2.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element2.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element3.segments_num
        if tree.element3.segments(i).subseg~=2
            row_num=size(tree.element3.segments(i).end,1);
            if all(tree.element3.segments(i).end(row_num,:)<axisx_L) && all(tree.element3.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element3.segments(i).rad;
                vsegment.level=tree.element3.segments(i).level;
                vsegment.istrunk=tree.element3.segments(i).istrunk;
                vsegment.start=tree.element3.segments(i).start;
                vsegment.end=tree.element3.segments(i).end;
                tree.element3.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element3.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element4.segments_num
        if tree.element4.segments(i).subseg~=2
            row_num=size(tree.element4.segments(i).end,1);
            if all(tree.element4.segments(i).end(row_num,:)<axisx_L) && all(tree.element4.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element4.segments(i).rad;
                vsegment.level=tree.element4.segments(i).level;
                vsegment.istrunk=tree.element4.segments(i).istrunk;
                vsegment.start=tree.element4.segments(i).start;
                vsegment.end=tree.element4.segments(i).end;
                tree.element4.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element4.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element5.segments_num
        if tree.element5.segments(i).subseg~=2
            row_num=size(tree.element5.segments(i).end,1);
            if all(tree.element5.segments(i).end(row_num,:)<axisx_L) && all(tree.element5.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element5.segments(i).rad;
                vsegment.level=tree.element5.segments(i).level;
                vsegment.istrunk=tree.element5.segments(i).istrunk;
                vsegment.start=tree.element5.segments(i).start;
                vsegment.end=tree.element5.segments(i).end;
                tree.element5.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element5.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element6.segments_num
        if tree.element6.segments(i).subseg~=2
            row_num=size(tree.element6.segments(i).end,1);
            if all(tree.element6.segments(i).end(row_num,:)<axisx_L) && all(tree.element6.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element6.segments(i).rad;
                vsegment.level=tree.element6.segments(i).level;
                vsegment.istrunk=tree.element6.segments(i).istrunk;
                vsegment.start=tree.element6.segments(i).start;
                vsegment.end=tree.element6.segments(i).end;
                tree.element6.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element6.segments(i).subseg=2;
            end
        end
    end
end
if label==1
    for i=1:tree.element7.segments_num
        if tree.element7.segments(i).subseg~=2
            row_num=size(tree.element7.segments(i).end,1);
            if all(tree.element7.segments(i).end(row_num,:)<axisx_L) && all(tree.element7.segments(i).end(row_num,:)>0)
                vsegment.rad=tree.element7.segments(i).rad;
                vsegment.level=tree.element7.segments(i).level;
                vsegment.istrunk=tree.element7.segments(i).istrunk;
                vsegment.start=tree.element7.segments(i).start;
                vsegment.end=tree.element7.segments(i).end;
                tree.element7.segments(i).subseg=2;
                label=0;
                break;
            else
                tree.element7.segments(i).subseg=2;
            end
        end
    end
end
end

